package GuessGame;

public class GuessNumberGame {
    GuessNumberPlayer Player01;
    GuessNumberPlayer Player02;
    GuessNumberPlayer Player03;

    public void startGame(){
        Player01 = new GuessNumberPlayer();
        Player02 = new GuessNumberPlayer();
        Player03 = new GuessNumberPlayer();

        int guessP1;
        int guessP2;
        int guessP3;

        boolean p1isright = false;
        boolean p2isright = false;
        boolean p3isright = false;

        int targetNumber = (int)(Math.random() * 10);   //谜底数字
        System.out.println("我正在想一个0-9之间的数");

        while (true){
            System.out.println("谜底是" +targetNumber);

            Player01.guess();
            Player02.guess();
            Player03.guess();

            guessP1 = Player01.number;
            System.out.println("第一次猜的是" + guessP1);
            guessP2 = Player02.number;
            System.out.println("第二次猜的是" + guessP2);
            guessP3 = Player03.number;
            System.out.println("第三次猜的是" + guessP3);

            if (guessP1 == targetNumber){
                p1isright = true;
            }
            if (guessP2 == targetNumber){
                p2isright = true;
            }
            if (guessP3 == targetNumber){
                p3isright = true;
            }

            if (p1isright||p2isright||p3isright){
                System.out.println("你赢了");
                System.out.println("第一次猜中了吗？"+ p1isright);
                System.out.println("第二次猜中了吗？"+ p2isright);
                System.out.println("第三次猜中了吗？"+ p3isright);
                break;
            }
            else{
                System.out.println("请再试一次。");
            }
        }
    }
}
